package logic

import (
	"context"
	"product666/model/redis"

	"product666/userrpc/internal/svc"
	"product666/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikelistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikelistLogic {
	return &LikelistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikelistLogic) Likelist(in *userrpc.LikelistRequest) (*userrpc.LikelistResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Client.ZRangeWithScores("like", 0, 9)
	var pro []*userrpc.Likelist
	for _, z := range scores.Val() {
		likelist := userrpc.Likelist{
			Title:  z.Member.(string),
			Number: int64(z.Score),
		}
		pro = append(pro, &likelist)
	}
	return &userrpc.LikelistResponse{Likelist: pro}, nil
}
